package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/application")
public class ApplicationController {

    @Autowired
    private ApplicationService applicationService;

    @PostMapping("save")
    public JsonResult sava( ApplicationSaveParam param){
        log.debug("{}",param);
        applicationService.sava(param);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult select(ApplicationQuery query){
        log.debug("{}",query);
       List<ApplicationVO> applicationVO = applicationService.select(query);
        return JsonResult.ok(applicationVO);
    }
    @PostMapping("cancel")
    public JsonResult cancel(Long id){
        log.debug("{}",id);
        applicationService.update(id);
        return JsonResult.ok();
    }
    @PostMapping("distribute/{applicationId}/{vehicleId}")
    public JsonResult distribute(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("{}",applicationId);
        log.debug("{}",vehicleId);
        applicationService.distribute(applicationId,vehicleId);
        return JsonResult.ok();
    }
    /**
     * 换车
     */
    @PostMapping("return/{applicationId}")
    public JsonResult returnVehicle(@PathVariable Long applicationId){
        log.debug("{}",applicationId);
        applicationService.applicationUp(applicationId);
        return JsonResult.ok();
    }
}
